package com.leetcode.No2180;

import org.junit.Test;

/**
 * 统计各位数字之和为偶数的整数个数
 */
public class Solution {
    public int countEven(int num) {
        int ans = 0;
        for (int i = 2; i <= num; ++i) {
            if (isIt(i)) {
                ++ans;
            }
        }
        return ans;
    }

    private boolean isIt(int num) {
        int flag = 0;
        while (num > 0) {
            flag ^= num;
            num /= 10;
        }
        return( flag & 1) == 0;
    }

    @Test
    public void test1() {
        int num;

        num = 4;
        System.out.println(countEven(num));

        num = 30;
        System.out.println(countEven(num));
    }
}
